using LispLib;
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Noein.Control;

namespace Noein.GeneticAlgorithm.New
{
    

    public class Population : IEnumerator, IEnumerable
    {
        private List<Individual> members;

        public Population(int size)
        {
            // TODO population initialization
        }

        public int Count
        {
            get { return members.Count; }
        }

        public Individual Get(int index)
        {
            return members[index];
        }

        public void Add(Population newMembers)
        {
            members.AddRange(newMembers.members);
        }

        public void SortByFitness()
        {
            members.Sort(
                delegate (Individual x, Individual y)
                {
                    float f = x.Fitness - y.Fitness;
                    if (f < 0)
                        return -1;
                    else if (f > 0)
                        return 1;
                    else
                        return 0;
                });
        }

        #region IEnumerator Members

        private int position = -1;

        public object Current
        {
            get { return members[position]; } 
        }

        public bool MoveNext()
        {
            position++; 
            return position < members.Count; 
        }

        public void Reset()
        {
            position = -1;
        }

        #endregion

        #region IEnumerable Members

        public IEnumerator GetEnumerator()
        {
            return (IEnumerator)this;
        }

        #endregion
    }
}
